package com.czkevin.cifjiaocheng;

import com.czkevin.cifjiaocheng.cif.*;
import com.czkevin.cef.CustomEntityRegister;
import com.czkevin.cifaddon.blockentity.advfurnace.fuel.AdvancedFuelRegister;
import com.czkevin.cifaddon.blockentity.advfurnace.fuel.Fuel;
import com.czkevin.cifaddon.blockentity.advfurnace.recipe.AdvancedFurnaceCIFInputRecipe;
import com.czkevin.cifaddon.blockentity.advfurnace.recipe.AdvancedFurnaceRecipeRegister;
import com.czkevin.cif.CIFItem;
import com.czkevin.cif.CIFItemInstance;
import com.czkevin.cif.CustomItemFramework;
import com.czkevin.cif.ItemRegister;
import com.czkevin.cif.crafting.RecipeRegister;
import com.czkevin.cif.crafting.ingredient.CIFCraftingIngredient;
import com.czkevin.cif.crafting.ingredient.VanillaCraftingIngredient;
import com.czkevin.cif.crafting.recipe.CIFRecipe;
import com.czkevin.cifjiaocheng.cef.ShitTNTEntity;
import org.bukkit.Material;
import org.bukkit.inventory.ItemStack;
import org.bukkit.plugin.java.JavaPlugin;

public final class JiaoCheng extends JavaPlugin {

    @Override
    public void onEnable() {
        // 注册一下，就像拉屎一样简单（除非你便秘）
        ItemRegister.register(new CeShiWuPin());
        ItemRegister.register(new ShitTNT());
        ItemRegister.register(new Toilet());

        ItemRegister.register(new ShitOre());
        ItemRegister.register(new SepticTank());
        ItemRegister.register(new Shit());
        ItemRegister.register(new DriedShit());

        // 注册一下ShitTNTEntity实体
        // 因为方块在激活之后会变成实体
        CustomEntityRegister.getInstance().register(ShitTNTEntity.class);

        // 注册合成表
        registerRecipes();
    }

    private void registerRecipes() {
        // 恶臭物品
        {
            // 写个合成表
            CIFRecipe r = new CIFRecipe(
                "sui_bian_yi_ge_ming_zi",
                ItemRegister.get("CeShiWuPin").generateItemStack(null, false),
                "ppp",
                "pbp",
                "ppp"
            );
            r.setIngredient('p', new VanillaCraftingIngredient(
                new ItemStack(Material.POISONOUS_POTATO) // 有毒的土豆
            ));
            r.setIngredient('b', new VanillaCraftingIngredient(
                new ItemStack(Material.BONE_BLOCK) // 骨头块
            ));

            // 注册合成表
            RecipeRegister.register(r);
        }

        // 恶臭TNT
        {
            CIFRecipe r = new CIFRecipe(
                "shit_tnt_recipe",
                ItemRegister.get("ShitTNT").generateItemStack(null, false),
                "ttt",
                "tet",
                "ttt"
            );
            r.setIngredient('t', new VanillaCraftingIngredient(new ItemStack(Material.TNT)));
            r.setIngredient('e', new CIFCraftingIngredient(new CIFItemInstance(ItemRegister.get("CeShiWuPin"))));

            RecipeRegister.register(r);
        }

        // 烘干的Shit可以用来当燃料烧30秒
        {
            AdvancedFuelRegister.getInstance().register(
                new Fuel() {
                    @Override
                    public boolean matches(ItemStack itemStack) {
                        if(itemStack == null || itemStack.getType() == Material.AIR) return false;
                        CIFItem type = CustomItemFramework.getCIFTypeFromItem(itemStack);
                        if(type == null || !DriedShit.class.isAssignableFrom(type.getClass())) return false;
                        return true;
                    }

                    @Override
                    public long getBurningTicks() {
                        return 30 * 20L;
                    }
                }
            );
        }

        // 普通Shit可以通过高级熔炉烘干
        AdvancedFurnaceRecipeRegister.register(
            new AdvancedFurnaceCIFInputRecipe(
                "shit_to_dried_shit",
                new CIFItemInstance(ItemRegister.get("Shit")),
                ItemRegister.get("DriedShit").generateItemStack(null, false),
                false,
                100
            )
        );
    }

}
